import { mergeConfig, defineConfig } from 'vite';
import baseConfig from './vite.config.base';
import configVisualizerPlugin from './plugin/visualizer';
// import configArcoResolverPlugin from './plugin/arcoResolver';
import configImageminPlugin from './plugin/imagemin';
import viteEnv from './vite.env';

export default defineConfig(({ mode }) => {
  return mergeConfig(
    {
      mode: 'production',
      base: viteEnv[mode].VITE_PUBLIC_PATH,
      plugins: [
        configVisualizerPlugin(),
        // configArcoResolverPlugin(),
        configImageminPlugin(),
      ],
      build: {
        rollupOptions: {
          output: {
            manualChunks: {
              arco: ['@arco-design/web-vue'],
              chart: ['echarts', 'vue-echarts'],
              vue: ['vue', 'vue-router', 'pinia', '@vueuse/core', 'vue-i18n'],
            },
          },
        },
        chunkSizeWarningLimit: 2000,
      },
      define: {
        'process.env': {
          ...viteEnv[mode],
          runMode: 'build',
        },
      },
    },
    baseConfig
  );
});
